package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.Reservation;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.ReservationMapperSql;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Pang
 */
@Repository
public interface IReservationMapper {

    /**
     * 添加预订信息表
     * @param reservation
     * @return
     */
    @Insert("INSERT INTO g_reservation(reservation_id,guest_name,guest_phone,reservation_type,reservation_date,arrive_date," +
            "day_num,room_num,reservation_ptice,payment_type,reservation_comment,type_id,staff_id) VALUE(#{reservationId},#{guestName},#{guestPhone},#{reservationType},#{reservationDate},#{arriveDate},#{dayNum},#{roomNum},#{reservationPtice}," +
            "#{paymentType},#{reservationComment},#{typeId},#{staffId})")
    int insert(Reservation reservation);

    /**
     * 删除预订信息
     * @param ReservationId
     * @return
     */
    @Delete("DELETE FROM g_reservation WHERE reservation_id=#{reservationId}")
    int delete(Long ReservationId);

    /**
     * 修改预订信息
     * @param reservation
     * @return
     */
    @Update("UPDATE g_reservation SET guest_name=#{guestName},guest_phone=#{guestPhone},reservation_type=#{reservationType},reservation_date=#{reservationDate},arrive_date=#{arriveDate},day_num=#{dayNum},room_num=#{roomNum},reservation_ptice=#{reservationPtice}," +
            "payment_type=#{paymentType},reservation_state=#{reservationState},reservation_comment=#{reservationComment},type_id=#{typeId},staff_id=#{staffId} WHERE reservation_id=#{reservationId}")
    int update(Reservation reservation);

    /**
     * 条件查询
     * @param
     * @return
     */
    @SelectProvider(type = ReservationMapperSql.class,method = "selectByAll")
    @Results(value = {
            @Result(column = "type_id",property = "roomType",one = @One(select = "com.xuetang9.t9.hotel.mapper.IRoomTypeMapper.selectById",fetchType = FetchType.EAGER)),
            @Result(column = "staff_id",property = "staffInfo",one = @One(select = "com.xuetang9.t9.hotel.mapper.IStaffInfoMapper.selectById",fetchType = FetchType.EAGER))
    })
    List<Reservation> selectByAll(@Param("key") ICondition condition);

    /**
     * 获取条件查询总数
     * @param
     * @return
     */
    @SelectProvider(type = ReservationMapperSql.class,method = "selectByCount")
    Long selectByCount(@Param("key") ICondition condition);


    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_reservation WHERE reservation_id =#{id}")
    Reservation selectByOne(@Param("id") Long id);
}
